<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/17
 * Time: 1666:23
 */
$ws = new swoole_websocket_server('0.0.0.0', 8899);

$ws->on('open',function($ws, $request){
    echo "\r\n";
    echo "server: handshake success with client:{$request->fd}\n";
});

$ws->on('message',function($ws, $frame){
    echo "receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}\n";
    $ws->push($frame->fd, "this is server time: ". date("Y-m-d H:i:s"));
});

$ws->on('close', function($ws, $fd){
    echo "client: {$fd} closed\n";
});

$ws->start();
